<include file="./Template/Admin/header.html" title="修改产品" />
<link rel="stylesheet" type="text/css" href="__ADMIN__css/plugins/webuploader/webuploader.css" />
<link rel="stylesheet" type="text/css" href="__ADMIN__js/plugins/webuploader/style.css" />
<link rel="stylesheet" type="text/css" href="__ADMIN__css/plugins/sweetalert/sweetalert.css" />
<style type="text/css">
    .divX
    {
        z-index:100;
        border-style:solid;
        border-width:1px;
        border-color:#FF0000;
        -moz-border-radius:20px;
        -webkit-border-radius:20px;
        background-color:#ffffff;
        line-height:10px;
        text-align:center;
        font-weight:bold;
        cursor:pointer;
        font-size:10px;
        color:red;
        display: none;
    }
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>修改产品</h5>
                </div>
                <div class="ibox-content">
                    <div class="row m-b-sm m-t-sm">
                        <div class="col-md-2">
                            <a href="{:U('Admin/product/index')}" class="btn btn-outline btn-primary">返回产品列表</a>
                        </div>
                    </div>
                    <form class="form-horizontal m-t" id="addForm" enctype="multipart/form-data" action="{:U('Admin/Product/Save')}">
                        <input type="hidden" id="code" name="code" value="{$productInfo.code}">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">产品名称:</label>
                            <div class="col-sm-8">
                                <input id="title" name="title" class="form-control" type="text" value="{$productInfo.title}" aria-required="true" aria-invalid="false" class="valid">
                                <input id="id" name="id" value="{$productInfo.id}" class="form-control" type="hidden">
                                <span class="help-block m-b-none"></span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <!--<div class="form-group">-->
                            <!--<label class="col-sm-3 control-label">产品图片:</label>-->
                            <!--<div class="col-sm-8">-->
                                <!--<input id="images" name="images" class="form-control" type="file" aria-required="true" aria-invalid="false" class="valid">-->
                            <!--</div>-->
                        <!--</div>-->
                        <div class="form-group">
                            <label class="col-sm-3 control-label">产品图片：</label>
                            <input type="hidden" id="images" name="images">
                            <div class="col-sm-8 control-label">
                                <foreach name="picture" item="vo" >
                                    <span style="position: relative;"id="span{$key}"><img id="{$key}" alt="{$key}" src="/{$vo}"  onmouseover="showDeleteDiv('{$key}');" onmouseout="imgOnmouseout(),hideDeleteDiv('{$key}');" style="width:50px;height:50px;padding-left:10px;"/></span>
                                </foreach>
                                <div id="uploader">
                                    <div class="queueList">
                                        <div id="dndArea" class="placeholder">
                                            <div id="filePicker"></div>
                                            <p>或将照片拖到这里，单次最多可选300张</p>
                                        </div>
                                    </div>
                                    <div class="statusBar" style="display:none;">
                                        <div class="progress">
                                            <span class="text">0%</span>
                                            <span class="percentage"></span>
                                        </div>
                                        <div class="btns">
                                            <div id="filePicker2"></div><div class="uploadBtn">开始上传</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">产品类别:</label>
                            <div class="col-sm-8">
                                <select class="form-control m-b" name="cate_id">
                                    <option>-----请为产品选择所属类别-----</option>
                                    <foreach name="category" item="v">
                                        <option value="{$v.id}" <if condition="$v['id'] eq $productInfo['cate_id']">selected</if>>{$v.html}{$v.title}</option>
                                    </foreach>
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">年份:</label>
                            <div class="col-sm-8">
                                <input id="years" name="years" value="{$productInfo.years}" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">尺寸:</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="{$productInfo.size}" name="size" id="size" />
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">重量:</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="{$productInfo.weight}" name="weight" id="weight" />
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">关键词:</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="{$productInfo.keyword}" name="keyword" id="keyword" aria-required="true" aria-invalid="false" class="valid"/>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">产品介绍:</label>
                            <div class="col-sm-8">
                                <!-- 加载编辑器的容器 -->
                                <script id="content" name="content" type="text/plain" >{$productInfo.content}</script>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">联系电话:</label>
                            <div class="col-sm-8">
                                <input type="text" class="form-control" value="<if condition="$productInfo['tel'] == ''">400-088-9783<else />{$productInfo.tel}</if>" name="tel" id="tel" aria-required="true" aria-invalid="false" class="valid"/>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>



<script src="__ADMIN__js/jquery.min.js"></script>
<script src="__ADMIN__js/bootstrap.min.js"></script>
<script src="__ADMIN__js/plugins/layer.3/layer.js"></script>
<script src="__ADMIN__js/common.js"></script>
<script src="__ADMIN__js/content.min.js"></script>
<script src="__ADMIN__js/plugins/validate/jquery.validate.min.js"></script>
<script src="__ADMIN__js/plugins/validate/messages_zh.min.js"></script>
<script src="__ADMIN__js/plugins/switchery/switchery.js"></script>

<script type="text/javascript" src="__ADMIN__js/plugins/webuploader/upload.js"></script>
<script type="text/javascript" src="__ADMIN__js/plugins/webuploader/webuploader.js"></script>
<script type="text/javascript" src="__ADMIN__js/plugins/sweetalert/sweetalert.min.js"></script>
<script type="text/javascript" src="__ADMIN__plugins/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__ADMIN__plugins/ueditor/ueditor.all.js"></script>

<script>
    var elem = document.querySelector('.js-switch');
    var init = new Switchery(elem);

    var ue = UE.getEditor('content');

    $(function(){
        $.validator.setDefaults({
            highlight: function (e) {
                $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
            }, success: function (e) {
                e.closest(".form-group").removeClass("has-error").addClass("has-success")
            }, errorElement: "span", errorPlacement: function (e, r) {
                e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
            }, errorClass: "help-block m-b-none", validClass: "help-block m-b-none"
        }), $().ready(function () {
            var e = "<i class='fa fa-times-circle'></i> ";

            $("#addForm").validate({
                rules: {
                    title: "required",
                    keyword: "required",
                    content: "required",
                    tel: "required",
                    cate_id: "required"
                },
                messages: {
                    title: e + "请输入产品名称",
                    keyword: e + "请输入产品的关键词",
                    content: e + "请输入产品介绍",
                    tel: e + "请输入联系电话",
                    cate_id: e + "请为产品选择所属类别"
                },
                submitHandler: function(form){
                    var data = new  FormData(document.getElementById('addForm'));
                    $.ajax({
                        url:$(form).attr('action'),
                        type:"POST",
                        data:data,
                        cache: false,
                        processData:false,
                        contentType:false,
                        success:function(data){
                            if(data.status > 0){
                                common.error(data.msg);
                            }else{
                                common.success(data.msg,"{:U('Admin/Product/index')}");
                            }
                        },
                        dataType:'JSON'
                    });
                    return false;
                }
            });
        });

    });
</script>
<script type="text/javascript">
    var imgFlag = false; //鼠标放在图片上标记
    var divFlag = false; //鼠标放在删除层上标记
    var id = {$productInfo.id};
    function showDeleteDiv(resourceCode){
        imgFlag = true;
        $("#"+resourceCode+"DIV").css("display","block");
    };

    function hideDeleteDiv(resourceCode){
        if(!imgFlag && !divFlag){
            $("#"+resourceCode+"DIV").css("display","none");
        }
    };

    function imgOnmouseout(){
        imgFlag=false;
    };

    function divOnmouseover(resourceCode){
        divFlag = true;
        showDeleteDiv(resourceCode);
    };

    function divOnmouseout(resourceCode){
        divFlag = false;
        if(imgFlag){
            showDeleteDiv(resourceCode);
        }else{
            hideDeleteDiv(resourceCode);
        }
    };

    function removeGroupNotActivitySharingPhotoByResourceCode(pic) {
        swal({
                    title: "您确定要删除这条信息吗?",
                    text: "删除后将无法恢复，请谨慎操作！",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的，我就是要删除！",
                    cancelButtonText: "师傅刹一脚...",
                    closeOnConfirm: false,
                    closeOnCancel: false
                },
                function(isConfirm){
                    if (isConfirm) {
                        $.ajax({
                            type:"post",
                            url:"{:U('Product/imgdel')}",
                            dataType:"json",
                            data:{"pic":pic,"id":id},
                            success:function (data) {
                                console.log(data);
                            }
                        }).done(function(data){
                            swal({
                                title:'永久删除！',
                                text:'删除成功',
                                type:'success',
                                confirmButtonText: "OK！"
                            },function(){
                                $("#span"+pic).remove();
                            });
                        }).error(function(data) {
                            swal("OMG", "删除操作失败了!", "error")
                        });
                    } else {
                        swal("已取消", "您取消了删除操作！", "error");
                    }
                });

    }

</script>
<script type="text/javascript">
    $(document).ready(function(){
        $("img").each(function(i){
            var divObj=$("<div onclick=removeGroupNotActivitySharingPhotoByResourceCode('"+$(this).attr('alt')+"'); onmouseover=divOnmouseover('"+$(this).attr('alt')+"'); onmouseout=divOnmouseout('"+$(this).attr('alt')+"');>×</div>");
            divObj.addClass("divX");
            divObj.attr("id",$(this).attr("alt")+"DIV");
            divObj.attr("title","删除图片"+$(this).attr('alt'));
            divObj.css({position:"absolute", left: $(this).position().left+45, top:$(this).position().top-10});
            $(this).parent().append(divObj);
        });
    });
</script>
</body>
</html>
